home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / plotting / pcgplots / gptcgm1.cpp < prev    next >
C/C++ Source or Header  |  1992-04-24  |  4KB  |  184 lines

  1. // GptCGM.cpp
  2. // copyright 1992 Pittsburgh Supercomputing Center
  3. #include <windows.h>
  4. #include "cgmio.h"
  5. #include "gpta.h"
  6.  
  7. cgmObject::cgmObject(CgmWindowPt win, FileObjectPt fobj )
  8.     {
  9.    cgmWin = win;
  10.     file = fobj;
  11.     cgm =NULL;
  12.     cgmMeta =NULL;
  13.     IsIndexed = FALSE;
  14.     curPic =NULL;
  15.     lastPic =NULL;
  16.     hMeta = NULL;
  17.     PicNum = 1;
  18.     Pictures = 0;
  19.     DidFullMeta = FALSE;
  20.     hCompBit     = NULL;
  21.     hMemDC   = NULL;
  22.     hOldBit = NULL;
  23.  
  24.     }
  25.  
  26.  
  27. cgmObject::~cgmObject(void)
  28.  {
  29.   ZapLastPic();
  30.   delete cgm;
  31.   //if (hMeta)DeleteMetaFile(hMeta);
  32.   if (hMemDC)
  33.     {
  34.     SelectObject(hMemDC, hOldBit);
  35.     DeleteDC(hMemDC);
  36.     DeleteObject(hCompBit);
  37.     }
  38.  }
  39.  
  40. BOOL cgmObject::NextPageExists(void)
  41.  { if (!curPic) return FALSE;
  42.     if ( curPic->next )     return TRUE;
  43.     else
  44.         {
  45.         Pictures = PicNum;
  46.         IsIndexed = TRUE;
  47.         return FALSE;
  48.         }
  49.   }
  50. BOOL cgmObject::PrevPageExists(void)
  51.  { if (curPic && curPic->prev ) return TRUE;    else return FALSE; }
  52.  
  53.  
  54. void cgmObject::ZapLastPic()
  55.     {
  56.     if (lastPic)  lastPic->setAside();
  57.     if (hMeta) {DeleteMetaFile(hMeta); hMeta = NULL;}
  58.  
  59.     }
  60.  
  61. void cgmObject::ReadCurPic() { if (curPic) curPic->readIn(); }
  62.  
  63. // *** CgmObject::WriteMetaFile  - Write Out Windows Metafile to Disk
  64. void cgmObject::WriteMetaFile(FileObjectPt FObjMeta)
  65.     {
  66.     // Put Metafile on disk
  67.     char filename[150];
  68.     strcpy(filename,  FObjMeta->GetFileName() );
  69.     HANDLE hNewMeta = CopyMetaFile(hMeta, filename);
  70.     hMeta = hNewMeta;
  71.     }
  72.  
  73. // *** CgmObject::MakeClearText  - generate clear text file
  74. void cgmObject::MakeClearText(FileObjectPt FObj)
  75.     {
  76.  
  77.     cgmEndMetafile myEnd; // for convenience
  78.     ClearOutputPt myOutput = new clearOutput("", FObj->GetHandle() );
  79.     cgmMeta->cgmOut(myOutput);
  80.     // force the end
  81.     myEnd.cgmOut(myOutput);
  82.     delete myOutput;
  83.     }
  84.  
  85. // *** cgmObject::IndexCgm()
  86. WORD cgmObject::IndexCgm()
  87.     {
  88.     CgmPicturePt Pic;
  89.     if ( IsIndexed ) return Pictures;
  90.     if (!cgmMeta) return 0;
  91.     cgmMeta->makeIndex();
  92.     for( Pictures = 1, Pic= cgmMeta->firstPic;Pic = Pic->next; Pictures++);
  93.     IsIndexed = TRUE;
  94.     return Pictures;
  95.     }
  96.  
  97. // *** cgmObject::GetPictureText()
  98. void cgmObject::GetPictureText(PSTR text, void **picture)
  99.     {
  100.     *text = 0;
  101.     CgmPicturePt pic = (CgmPicturePt)*picture;
  102.     if (!cgmMeta) { *picture = NULL;  return; }
  103.     if (!pic) pic = cgmMeta->firstPic;
  104.     if (pic->name() )  strcpy( text, pic->name());
  105.     *picture = pic->next;
  106.     }
  107.  
  108. // *** cgmObject::GetSel()
  109. BOOL cgmObject:: GetSel( void **picture)
  110.     {
  111.     BOOL WantIt = FALSE;
  112.     CgmPicturePt pic = (CgmPicturePt)*picture;
  113.     if (!cgmMeta || !IsIndexed)
  114.         { *picture = NULL;  return FALSE; }
  115.     if (!pic) pic = cgmMeta->firstPic;
  116.     if (pic->want()) WantIt = TRUE;
  117.     *picture = pic->next;
  118.     return WantIt;
  119.     }
  120.  
  121. // *** cgmObject::SetSel()
  122. void cgmObject:: SetSel(BOOL WantIt, void **picture)
  123.     {
  124.     CgmPicturePt pic = (CgmPicturePt)*picture;
  125.     if (!cgmMeta )
  126.         { *picture = NULL;  return; }
  127.     if (!pic) pic = cgmMeta->firstPic;
  128.     pic->setWant(WantIt);
  129.     *picture = pic->next;
  130.     }
  131.  
  132. // *** cgmObject::NextPage()
  133. BOOL cgmObject::NextPage()
  134.     {
  135.     if ( !NextPageExists() ) return FALSE;
  136.     CgmPicturePt pic = curPic->next;
  137.     curPic = pic;
  138.     PicNum++;
  139.     // Force Redraw
  140.     return TRUE;
  141.     }
  142.  // *** cgmObject::NewPage()
  143. BOOL cgmObject::NewPage(WORD Page)
  144.     {
  145.     int i;
  146.     for( i=1, curPic= cgmMeta->firstPic; i < Page;i++)
  147.         curPic = curPic->next;
  148.     PicNum = Page;
  149.     return TRUE;
  150.     }
  151.  
  152.  // *** cgmObject::PreviousPage()
  153. BOOL cgmObject::PreviousPage()
  154.     {
  155.     if ( !PrevPageExists() ) return FALSE;
  156.     CgmPicturePt pic = curPic->prev;
  157.     curPic = pic;
  158.     PicNum--;
  159.     // Force Redraw
  160.     return TRUE;
  161.     }
  162. // *** CgmObject::GplotInit  - find metafile and get to first picture
  163. void cgmObject::GPlotInit( )
  164.      {
  165.      cgmMetafile *metafile;
  166.      cgm = new cgmFile(file->GetFileName(),file->GetHandle());
  167.      if (!cgm) return;
  168.      if (!(cgmMeta = cgm->foundMetafile()))
  169.          {
  170.          myError("no metafile in", file->GetFileName(), 0); // exits
  171.          delete cgm;
  172.          cgm = NULL;
  173.          return;
  174.          }
  175.       curPic = cgmMeta->firstPic;
  176.       if (!curPic)
  177.          {
  178.          myError("no pictures in file", file->GetFileName(), 0); // exits
  179.          delete cgm;
  180.          cgm = NULL;
  181.          return;
  182.          }
  183.     }
  184.